package com.dong.filter;

import com.dong.pojo.User;
import com.dong.util.Constants;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SysFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest Req, ServletResponse Resp, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) Req;
        HttpServletResponse response = (HttpServletResponse) Resp;

        //过滤器，由session中获取用户
        User user = (User) request.getSession().getAttribute(Constants.USER_SESSION);
        if(user == null){//如果用户登录或者注销
            response.sendRedirect("/smbms/error.jsp");
        }else{
            filterChain.doFilter(Req,Resp);
        }
    }

    public void destroy() {

    }
}
